<template>
<div>
    <homeheader ></homeheader>  
    <homeswiper :list="swiperList"></homeswiper>
    <homeicons  :list="iconList"></homeicons>
    <recommend  :list="recommendList"></recommend>  
    <homeweeked :list="weekendList"></homeweeked>
</div>
</template>

<script>
import {mapState} from 'vuex'
import homeheader from './components/header'
import homeswiper from './components/swiper'
import homeicons from './components/icons'
import recommend from './components/recommend'
import homeweeked from './components/weekend'
import axios from 'axios'
export default {
  name:'home',
  components: {
    homeheader,
    homeswiper,
    homeicons,
    recommend,
    homeweeked
  },
  data () {
    return {
      lastcity:[],
      swiperList:[],
      iconList:[],
      recommendList:[],
      weekendList:[]
    }
  },
  computed:{
    ...mapState(['city'])
  },
  // axios.get('/static/mock/index.json')
  methods:{
    getgomeinfo () {
      axios.get('/static/mock/index.json?city='+this.city)
        .then(this.gethomrinfosuc)
    },
    gethomrinfosuc(res){
     res=res.data
     if(res.ret && res.data){
       const data=res.data
       this.swiperList=data.swiperList
       this.iconList=data.iconList
       this.recommendList=data.recommendList
       this.weekendList=data.weekendList
     }
    }
  },
  mounted() {
    this.lastcity=this.city
    this.getgomeinfo()
    console.log("activated11")
  },
  activated() {
    console.log("activated")
     if(this.lastcity!==this.city){  //值不同的时候发生改变
       this.lastcity=this.city  //让上一次城市发生改变
         this.getgomeinfo() //
          console.log("进入activated")
     }
  }

}
</script>

<style lang="stylus" scoped>

 
</style>


